clear all
set more off
capture log close
pause on

* This .do file starts with the file attachment sent on Oct 22 2021.  SC altered the top row manually to create some variable names in the .csv



/* SC */ capture cd "/Users/robertchaudoin/Dropbox/Kill_Scrapes/IO Reviews/Survey/Data/"
/* SC */ cd "/Users/stephenchaudoin/Dropbox/Kill_Scrapes/IO Reviews/Survey/Data/"

import delimited using "21072005 Harvard Philippines Final Data 22102021_manualcolumnnames", clear

rename ïstatus status
drop if status != "Complete"

*** Survey dates; times
split endtime, parse(" ") generate(end_)
split timespent, parse(":") generate(timespent_)
gen timespent_seconds = .
destring timespent_1, replace
destring timespent_2, replace
destring timespent_3, replace

replace timespent_seconds = 60*timespent_1 + timespent_2 if timespent_3 == .
replace timespent_seconds = 60*60*timespent_1 + 60*timespent_2 + timespent_3 if timespent_3 != .

gen speederorslow = 0
replace speederorslow = 1 if timespent_seconds < 180 | timespent_seconds > 600 

*** Party
gen pdpl = 0
replace pdpl = 1 if party1 == "PDP-Laban"
replace pdpl = 1 if strpos(party2, "aban")


gen libparty = 0
replace libparty = 1 if party1 == "Liberal"
replace libparty = 1 if strpos(party2, "Leni") | strpos(party2, "Liberal") | strpos(party2, "Makbayan")

gen not_pdpl_libparty = 0
replace not_pdpl_libparty = 1 if party1 != "PDP-Laban" & party1 != "Liberal"


*** Treatment groups by party
gen treatment_groupA = 0
replace treatment_groupA = 1 if strpos(treatment, "Group A")

gen treatment_groupB = 0
replace treatment_groupB = 1 if strpos(treatment, "Group B")

gen treatment_groupC = 0
replace treatment_groupC = 1 if strpos(treatment, "Group C")

* TGM manually deleted one respondent where the blocking didn't work.  She answered Liberal Party, but was assigned to Treatment control - Group A.  She shows up in the September file, but not the October 1 file.
*tab treatment if libparty == 1
*bro if libparty == 1 & treatment_groupB != 1


*** Treatment groups by treatment/control
gen treatment_ctrl = 0 
replace treatment_ctrl = 1 if strpos(treatment, "control")

gen treatment_wod = 0 
replace treatment_wod = 1 if strpos(treatment, "1")

gen treatment_icccontest = 0 
replace treatment_icccontest = 1 if strpos(treatment, "2")

gen treatment_iccnocontest = 0 
replace treatment_iccnocontest = 1 if strpos(treatment, "3")

gen treatment_factor = ""
replace treatment_factor = "Control" if treatment_ctrl == 1
replace treatment_factor = "ICC Contest" if treatment_icccontest == 1
replace treatment_factor = "ICC No Contest" if treatment_iccnocontest == 1
replace treatment_factor = "WOD" if treatment_wod == 1

*** Blocking check
* tab treatment if pdpl == 1
* tab treatment if libparty == 1
* tab treatment if not_pdpl_libparty == 1

*** Manual interatcion terms
foreach v in treatment_ctrl treatment_icccontest treatment_iccnocontest treatment_wod {
	gen `v'_lib = `v'*libparty
	gen `v'_pdpl = `v'*pdpl
}


*** Manipulation check; by blocking groups
bysort treatment: tab manipcheck
*	Generally good, except for the control.  Still answering ICC but that makes sense because of the outcome questions.
bysort treatment_ctrl: tab manipcheck
tab manipcheck if treatment_icccontest == 1
tab manipcheck if treatment_iccnocontest == 1
tab manipcheck if treatment_wod == 1
tab manipcheck if treatment_icccontest == 1 | treatment_iccnocontest == 1

tab manipcheck if treatment_wod == 1 & speederorslow == 0
tab manipcheck if treatment_icccontest == 1 | treatment_iccnocontest == 1 & speederorslow == 0


*** Outcome measures

* Support for the WOD
gen supportwod_bin = 0
replace supportwod_bin = 1 if supportwod == "Support" | supportwod == "Truly support"

gen supportwod_bin_nn = 0
replace supportwod_bin_nn = 1 if supportwod == "Support" | supportwod == "Truly support"
replace supportwod_bin_nn = . if supportwod == "May support and may not support"

gen supportwod_num = .
replace supportwod_num = 0 if supportwod == "Truly not support"
replace supportwod_num = 1 if supportwod == "Not support"
replace supportwod_num = 2 if supportwod == "May support and may not support"
replace supportwod_num = 3 if supportwod == "Support"
replace supportwod_num = 4 if supportwod == "Truly support"

* Support for an ICC investigation
gen iccsupport_bin = 0
replace iccsupport_bin = 1 if supporticcinv == "Somewhat agree" | supporticcinv == "Strongly agree"

gen iccsupport_bin_nn = 0
replace iccsupport_bin_nn = 1 if supporticcinv == "Somewhat agree" | supporticcinv == "Strongly agree"
replace iccsupport_bin_nn = . if supporticcinv == "Neither agree nor disagree"

gen iccsupport_num = .
replace iccsupport_num = 0 if supporticcinv == "Strongly disagree"
replace iccsupport_num = 1 if supporticcinv == "Somewhat disagree"
replace iccsupport_num = 2 if supporticcinv == "Neither agree nor disagree"
replace iccsupport_num = 3 if supporticcinv == "Somewhat agree"
replace iccsupport_num = 4 if supporticcinv == "Strongly agree"

* ICC bias
gen iccbiased_bin = 0
replace iccbiased_bin = 1 if iccbiased == "Somewhat agree" | iccbiased == "Strongly agree"

gen iccbiased_bin_nn = 0
replace iccbiased_bin_nn = 1 if iccbiased == "Somewhat agree" | iccbiased == "Strongly agree"
replace iccbiased_bin_nn = . if iccbiased == "Neither agree nor disagree"

gen iccbiased_num = .
replace iccbiased_num = 0 if iccbiased == "Strongly disagree"
replace iccbiased_num = 1 if iccbiased == "Somewhat disagree"
replace iccbiased_num = 2 if iccbiased == "Neither agree nor disagree"
replace iccbiased_num = 3 if iccbiased == "Somewhat agree"
replace iccbiased_num = 4 if iccbiased == "Strongly agree"


* Satisfied with Duterte
gen dutertesat_bin = 0
replace dutertesat_bin = 1 if duterte == "Somewhat satisfied" | duterte == "Very satisfied"

gen dutertesat_bin_nn = 0
replace dutertesat_bin_nn = 1 if duterte == "Somewhat satisfied" | duterte == "Very satisfied"
replace dutertesat_bin_nn = . if duterte == "Undecided"

gen dutertesat_num = .
replace dutertesat_num = 0 if duterte == "Very dissatisfied"
replace dutertesat_num = 1 if duterte == "Somewhat dissatisfied"
replace dutertesat_num = 2 if duterte == "Undecided"
replace dutertesat_num = 3 if duterte == "Somewhat satisfied"
replace dutertesat_num = 4 if duterte == "Very satisfied"

* Sanity checks
*bysort pdpl: su dutertesat_num
*bysort libparty: su dutertesat_num


* Trust in various actors/institutions

foreach v in trustpdpl trustlp trustdomhr trustinthr {

gen `v'_bin = 0
replace `v'_bin = 1 if `v' == "A lot of trust" | `v' == "Some trust"

gen `v'_bin_nn = 0
replace `v'_bin_nn = 1 if `v' == "A lot of trust" | `v' == "Some trust"
replace `v'_bin_nn = . if `v' == "Neither a lot nor a little"

gen `v'_num = .
replace `v'_num = 0 if `v' == "No trust"
replace `v'_num = 1 if `v' == "Little trust"
replace `v'_num = 2 if `v' == "Neither a lot nor a little"
replace `v'_num = 3 if `v' == "Some trust"
replace `v'_num = 4 if `v' == "A lot of trust"	
	}
*


***
* Respondent characteristics setup
***

*** Female
gen female = 0
replace female = 1 if gender == "Female"

*** Ethnicity
* Making indicators for the two largest in the sample
gen cebuano = 0
replace cebuano = 1 if ethnicity1 == "Cebuano"

gen tagalog = 0
replace tagalog = 1 if ethnicity1 == "Tagalog" | ethnicity2 == "tagalog" | ethnicity2 == "Tagalog"

*** Religion
* Making a Catholic indicator
gen catholic = 0
replace catholic = 1 if religion1 == "Catholic"

*** Language the survey was taken in
*gen language_tagalog = 0
*replace language_tagalog = 1 if language == "Tagalog"

*** Education
* . table education, stubwidth(40)
gen education_postsec = 0
replace education_postsec = 1 if  strpos(education, "I am")

*** Income
* Constructed indicators for 0-25th percentiles, 26-75, and 76+
gen income_lower25th = 0
gen income_26thto75th = 0
gen income_above75th = 0

replace income_lower25th = 1 if income <= 17000
replace income_26thto75th = 1 if income > 17000 & income <= 50000
replace income_above75th = 1 if income > 50000

*** Newshours
* Median is 5
gen newshours_morethan5 = 0
replace newshours_morethan5 = 1 if newshours > 5

*** Other party variables

gen rightparty = 0
replace rightparty = 1 if party1 == "PDP-Laban" | party1 == "Lakas" | party1 == "NPC" | party1 == "NUP" | party1 == "Nacionalista" 

replace rightparty = 1 if party2 == "ACT-CIS" | party2 == "Agimat" | party2 == "Bagong Lipunan" | party2 == "CIBAC" | party2 == "DUTERTE" | party2 == "Duterte" | party2 == "LDP"

replace rightparty = 1 if strpos(party2, "BBM")
replace rightparty = 1 if strpos(party2, "bbm")
replace rightparty = 1 if strpos(party2, "Bagumbayan")
replace rightparty = 1 if strpos(party2, "DDS")
replace rightparty = 1 if strpos(party2, "dds")
replace rightparty = 1 if strpos(party2, "ederal")
replace rightparty = 1 if strpos(party2, "HNP")
replace rightparty = 1 if strpos(party2, "ugpong")
replace rightparty = 1 if strpos(party2, "KBL")
replace rightparty = 1 if strpos(party2, "Kbl")
replace rightparty = 1 if strpos(party2, "Kilusang")
replace rightparty = 1 if strpos(party2, "Laban")
replace rightparty = 1 if strpos(party2, "Lakas")
replace rightparty = 1 if strpos(party2, "Marcos")
replace rightparty = 1 if strpos(party2, "NPC")
replace rightparty = 1 if strpos(party2, "Nacionalista")
replace rightparty = 1 if strpos(party2, "Nationalis")
replace rightparty = 1 if strpos(party2, "PDP")
replace rightparty = 1 if strpos(party2, "Federal")
replace rightparty = 1 if strpos(party2, "laban")
replace rightparty = 1 if strpos(party2, "Present Administration")
replace rightparty = 1 if strpos(party2, "uterte")

gen notrightparty = 0
replace notrightparty = 1 if rightparty == 0


*** Marital status
gen married = 0
replace married = 1 if marital == "Married"

*** Region
* There are 17 regions coded; this is just an indicator for Metro Manila/NCR
gen metromanilancr = 0
replace metromanilancr = 1 if strpos(region, "Manila")



capture export delimited using "/Users/stephenchaudoin/Dropbox/Kill_Scrapes/replication code for IO/phlsurvey_working_data.csv", replace
